package com.hhit.zhgd.task

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
import com.hhit.zhgd.config.InitDictionaryConfig
import com.hhit.zhgd.domain.entity.ZhgdDictionary
import com.hhit.zhgd.service.ZhgdDictionaryService
import jakarta.annotation.Resource
import org.quartz.JobExecutionContext
import org.springframework.scheduling.quartz.QuartzJobBean

class SyncDictionaryTask : QuartzJobBean() {
    @Resource
    private val zhgdDictionaryService: ZhgdDictionaryService? = null


    override fun executeInternal(context: JobExecutionContext) {
        val parentCodes = zhgdDictionaryService?.list(
            QueryWrapper<ZhgdDictionary?>().eq("parent_code","").or().isNull("parent_code"))

        for (zhgdDictionary in parentCodes?: listOf()) {
            val codes = zhgdDictionaryService?.list(
                QueryWrapper<ZhgdDictionary?>().eq("parent_code", zhgdDictionary.parentCode))
            for (child in codes?: listOf()) {
                InitDictionaryConfig.DICTIONARY_MAP[String.format("%s/%s", zhgdDictionary.code, child.code)] = child.value
            }
        }
    }
}